<template>
  <div>
    <div style="margin-top: 5px; margin-bottom: 5px">
      <el-input
        v-model="name"
        placeholder="请输入物品名"
        style="width: 200px"
        @keyup.enter="loadPost"
        ><template><el-icon class="el-input__icon"></el-icon></template
      ></el-input>
      <el-select v-model="storage" placeholder="请选择仓库" style="width: 200px; margin: 0 10px">
        <el-option v-for="item in storageData" :key="item.id" :label="item.name" :value="item.id">
        </el-option>
      </el-select>
      <el-select v-model="goodstype" placeholder="请选择分类" style="width: 200px">
        <el-option v-for="item in goodstypeData" :key="item.id" :label="item.name" :value="item.id">
        </el-option>
      </el-select>
      <el-button type="primary" style="margin-left: 10px" @click="loadPost">查询</el-button>
      <el-button type="success" @click="resetParam">重置</el-button>
    </div>
    <el-table
      :data="tableData"
      style="height: 100"
      :header-cell-style="{ background: '#f2f5fc', color: '#555', textAlign: 'center' }"
      :cell-style="{ textAlign: 'center' }"
      border
      stripe
    >
      <el-table-column prop="id" label="ID" width="60" />
      <el-table-column prop="goodsname" label="物品名" width="100" />
      <el-table-column prop="storagename" label="仓库" />
      <el-table-column prop="goodstypename" label="分类" />
      <el-table-column prop="adminname" label="操作人" />
      <el-table-column prop="username" label="申请人" />
      <el-table-column prop="count" label="数量" />
      <el-table-column prop="createTime" label="操作时间" />
      <el-table-column prop="remark" label="备注" />
    </el-table>
    <div class="demo-pagination-block">
      <el-pagination
        v-model:current-page="pageNum"
        v-model:page-size="pageSize"
        :page-sizes="[5, 10, 20, 30]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        style="text-align: center"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import { ElMessageBox } from 'element-plus';
import { reactive } from 'vue';
export default {
  name: 'RecordManage',
  data() {
    return {
      user: JSON.parse(sessionStorage.getItem('User')),
      storageData: [],
      goodstypeData: [],
      tableData: [],
      pageSize: 10,
      pageNum: 1,
      total: 0,
      name: '',
      storage: '',
      goodstype: '',
      dialogVisible: false,
      form: {
        id: '',
        name: '',
        storage: '',
        goodstype: '',
        count: '',
        remark: '',
      },
    };
  },
  methods: {
    loadPost() {
      this.$axios
        .post(this.$httpUrl + '/record/listPage', {
          pageSize: this.pageSize,
          pageNum: this.pageNum,
          param: {
            name: this.name,
            goodstype: this.goodstype + '',
            storage: this.storage + '',
            roleId: this.user.roleId,
            userid: this.user.id,
          },
        })
        .then((res) => res.data)
        .then((res) => {
          if (res.code == 200) {
            this.tableData = res.data;
            this.total = res.total;
          } else {
            alert('获取数据失败');
          }
        });
    },
    resetParam() {
      this.name = '';
      this.storage = '';
      this.goodstype = '';
      this.loadPost();
    },
    handleSizeChange(val) {
      this.pageNum = 1;
      this.pageSize = val;
      this.loadPost();
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      this.loadPost();
    },
    loadStorage() {
      this.$axios
        .get(this.$httpUrl + '/storage/list')
        .then((res) => res.data)
        .then((res) => {
          if (res.code == 200) {
            this.storageData = res.data;
          } else {
            alert('获取数据失败');
          }
        });
    },
    loadGoodstype() {
      this.$axios
        .get(this.$httpUrl + '/goodstype/list')
        .then((res) => res.data)
        .then((res) => {
          if (res.code == 200) {
            this.goodstypeData = res.data;
          } else {
            alert('获取数据失败');
          }
        });
    },
  },
  created() {
    // this.loadGet();
    this.loadStorage();
    this.loadGoodstype();
    this.loadPost();
  },
};
</script>

<style scoped></style>
